package cn.xfdzx.android.apps.shop.fragment;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.activity.AfterSalesActivity;
import cn.xfdzx.android.apps.shop.activity.AllOrderActivity;
import cn.xfdzx.android.apps.shop.activity.CouponActivity;
import cn.xfdzx.android.apps.shop.activity.FeedbackActivity;
import cn.xfdzx.android.apps.shop.activity.ManagementAddressActivity;
import cn.xfdzx.android.apps.shop.activity.MerchantsInActivity;
import cn.xfdzx.android.apps.shop.activity.MessageActivity;
import cn.xfdzx.android.apps.shop.activity.MyFollowActivity;
import cn.xfdzx.android.apps.shop.activity.remake.MyRemakeActivity;
import cn.xfdzx.android.apps.shop.activity.RecommendedActivity;
import cn.xfdzx.android.apps.shop.activity.SettingActivity;
import cn.xfdzx.android.apps.shop.activity.ShopActivity;
import cn.xfdzx.android.apps.shop.activity.ShopFocusActivity;
import cn.xfdzx.android.apps.shop.activity.XFDGoodsDeatailsActivity;
import cn.xfdzx.android.apps.shop.activity.login.OneLoginMainActivity;
import cn.xfdzx.android.apps.shop.activity.myshop.MyShopCenterActivity;
import cn.xfdzx.android.apps.shop.adapter.OftenBuyAdapter;
import cn.xfdzx.android.apps.shop.apps.Constants;
import cn.xfdzx.android.apps.shop.base.BaseMvpFragment;
import cn.xfdzx.android.apps.shop.bean.BuyOftenGoodsBeen;
import cn.xfdzx.android.apps.shop.bean.PosterBeen;
import cn.xfdzx.android.apps.shop.bean.UserInfoBean;
import cn.xfdzx.android.apps.shop.contract.ItemClickListener;
import cn.xfdzx.android.apps.shop.contract.MyInterestGoodContract;
import cn.xfdzx.android.apps.shop.evenbus.FiveFragmentClickMessage;
import cn.xfdzx.android.apps.shop.evenbus.HomeTypeMessage;
import cn.xfdzx.android.apps.shop.evenbus.MyInfoRefreshMessage;
import cn.xfdzx.android.apps.shop.presenter.MyInterestGoodPresenter;
import cn.xfdzx.android.apps.shop.util.EmptyUtil;
import cn.xfdzx.android.apps.shop.util.ItemOffsetDecoration;
import cn.xfdzx.android.apps.shop.util.StatusBarUtil;
import cn.xfdzx.android.apps.shop.util.UtilsData;
import cn.xfdzx.android.apps.shop.view.IArcMyView;

import static cn.xfdzx.android.apps.shop.activity.MainActivity.TYPE_IS_RETAIL;
import static cn.xfdzx.android.apps.shop.apps.Constants.APP_TOKEN;

public class FiveFragment extends BaseMvpFragment<MyInterestGoodPresenter> implements View.OnClickListener, MyInterestGoodContract.View {

    LinearLayout llState;
    RecyclerView rvRecommendedForYou;
    TextView tvAllOrder;
    LinearLayout llMyShop;
    LinearLayout llShop;
    RelativeLayout rlTitle;
    IArcMyView iavBg;
    ImageView ivDaizhifu;
    ImageView ivDaiFahuo;
    ImageView ivPeisong;
    ImageView ivMyEvaluation;
    ImageView ivMyShou;
    LinearLayout llDaiZhi;
    LinearLayout llDaiFa;
    LinearLayout llDaiShou;
    LinearLayout llDaiPing;
    LinearLayout llShouHou;
    TextView tvDaiZhi, tvDaiFa, tvDaiShou, tvDaiPing, tvShouHou;
    LinearLayout llMyAddress;//我的地址
    LinearLayout llContactKefu;//联系客服
    LinearLayout llFeedback;//意见反馈
    LinearLayout llMyEvaluation;//我的评价
    LinearLayout llRecommendedPrize;//推荐有奖
    LinearLayout ll_set;//设置
    TextView tvShopRuzhu;//入驻
    private ImageView iv_message;
    private LinearLayout ll_shopfocus;//店铺关注
    private LinearLayout ll_coupon;//优惠券
    private LinearLayout ll_follow;//浏览记录

    OftenBuyAdapter oftenBuyAdapter;//我常买的物品
    ImageView ivMyHead;
    TextView tvName;
    private RelativeLayout.LayoutParams item_bar;

    SmartRefreshLayout mRefreshLayout;
    private List<BuyOftenGoodsBeen.DataBean> mList = new ArrayList<>();
    private int page;
    private int limit = Constants.LIMIT;//每页多少条

    private TextView tv_shop_focus_num;
    private TextView tv_follow_num;

    @Override
    protected void initView(View view) {
        mPresenter = new MyInterestGoodPresenter();
        mPresenter.attachView(this);
        EventBus.getDefault().register(this);
        tv_shop_focus_num = view.findViewById(R.id.tv_shop_focus_num);
        tv_follow_num = view.findViewById(R.id.tv_follow_num);
        llState = view.findViewById(R.id.ll_state);
        tvShopRuzhu = view.findViewById(R.id.tv_shop_ruzhu);
        ivMyHead = view.findViewById(R.id.iv_my_head);
        tvName = view.findViewById(R.id.tv_name);
        rvRecommendedForYou = view.findViewById(R.id.rv_recommended_for_you);
        tvAllOrder = view.findViewById(R.id.tv_all_order);
        llMyShop = view.findViewById(R.id.ll_my_shop);
        rlTitle = view.findViewById(R.id.rl_title);
        iavBg = view.findViewById(R.id.iav_bg);
        ivDaizhifu = view.findViewById(R.id.iv_daizhifu);
        ivDaiFahuo = view.findViewById(R.id.iv_dai_fahuo);
        ivPeisong = view.findViewById(R.id.iv_peisong);
        ivMyEvaluation = view.findViewById(R.id.iv_my_evaluation);
        ivMyShou = view.findViewById(R.id.iv_my_shou);
        llShop = view.findViewById(R.id.ll_shop);
        llDaiZhi = view.findViewById(R.id.ll_dai_zhi);
        llDaiFa = view.findViewById(R.id.ll_dai_fa);
        llDaiShou = view.findViewById(R.id.ll_dai_shou);
        llDaiPing = view.findViewById(R.id.ll_dai_ping);
        llShouHou = view.findViewById(R.id.ll_shou_hou);

        tvDaiZhi = view.findViewById(R.id.tv_dai_zhi);
        tvDaiFa = view.findViewById(R.id.tv_dai_fa);
        tvDaiShou = view.findViewById(R.id.tv_dai_shou);
        tvDaiPing = view.findViewById(R.id.tv_dai_ping);
        tvShouHou = view.findViewById(R.id.tv_shou_hou);

        llMyAddress = view.findViewById(R.id.ll_my_address);
        llContactKefu = view.findViewById(R.id.ll_contact_kefu);
        llFeedback = view.findViewById(R.id.ll_feedback);
        mRefreshLayout = view.findViewById(R.id.refreshLayout);
        ll_set = view.findViewById(R.id.ll_set);
        llMyEvaluation = view.findViewById(R.id.ll_my_evaluation);
        llRecommendedPrize = view.findViewById(R.id.ll_recommended_prize);
        iv_message = view.findViewById(R.id.iv_message);
        ll_shopfocus = view.findViewById(R.id.ll_shopfocus);//店铺关注
        ll_coupon = view.findViewById(R.id.ll_coupon);//优惠券
        ll_follow = view.findViewById(R.id.ll_follow);//浏览记录
        ll_shopfocus.setOnClickListener(this);
        ll_coupon.setOnClickListener(this);
        ll_follow.setOnClickListener(this);
        llDaiZhi.setOnClickListener(this);
        llDaiFa.setOnClickListener(this);
        llDaiShou.setOnClickListener(this);
        llDaiPing.setOnClickListener(this);
        llShouHou.setOnClickListener(this);
        tvAllOrder.setOnClickListener(this);
        llShop.setOnClickListener(this);
        llMyShop.setOnClickListener(this);
        llMyAddress.setOnClickListener(this);
        llContactKefu.setOnClickListener(this);
        llFeedback.setOnClickListener(this);
        ll_set.setOnClickListener(this);
        llMyEvaluation.setOnClickListener(this);
        ivMyHead.setOnClickListener(this);
        tvName.setOnClickListener(this);
        iv_message.setOnClickListener(this);
        llRecommendedPrize.setOnClickListener(this);

        initHigh();
        setInfo();//设置个人头像
        rvRecommendedForYou.setItemAnimator(new DefaultItemAnimator());
        GridLayoutManager mLayoutManager = new GridLayoutManager(getActivity(), 2);
        rvRecommendedForYou.setLayoutManager(mLayoutManager);
        ItemOffsetDecoration itemDecoration = new ItemOffsetDecoration(getContext(), R.dimen.item_offset);
        rvRecommendedForYou.addItemDecoration(itemDecoration);
        rvRecommendedForYou.setNestedScrollingEnabled(false);
        oftenBuyAdapter = new OftenBuyAdapter(getActivity(), mList);
        oftenBuyAdapter.setOnItemClickListener(new ItemClickListener() {
            @Override
            public void onItemClick(int position) {
                if (mList.get(position).getGoods_status() == 0) {
                    Intent intent = new Intent(getContext(), ShopActivity.class);
                    intent.putExtra("shop_id", mList.get(position).getStore_id() + "");
                    intent.putExtra("good_id", mList.get(position).getId() + "");
                    startActivity(intent);
                } else {
                    Intent intent = new Intent(getContext(), XFDGoodsDeatailsActivity.class);
                    intent.putExtra("good_id", mList.get(position).getId() + "");
                    startActivity(intent);
                }
            }
        });
        rvRecommendedForYou.setAdapter(oftenBuyAdapter);

        if (TYPE_IS_RETAIL == 0) {

            iavBg.setToColor("#fb9129");
            llState.setBackgroundColor(getResources().getColor(R.color.color_FB9129));
            ivDaizhifu.setImageResource(R.drawable.icon_my_daizhifu_orange);
            ivDaiFahuo.setImageResource(R.drawable.icon_my_dai_fahuo_orange);
            ivPeisong.setImageResource(R.drawable.icon_my_peisong_orange);
            ivMyEvaluation.setImageResource(R.drawable.icon_my_evaluation_orange);
            ivMyShou.setImageResource(R.drawable.icon_my_shou_orange);
        } else {

            iavBg.setToColor("#02C557");
            llState.setBackgroundColor(getResources().getColor(R.color.color_02C557));
            ivDaizhifu.setImageResource(R.drawable.icon_my_daizhifu_green);
            ivDaiFahuo.setImageResource(R.drawable.icon_my_dai_fahuo_green);
            ivPeisong.setImageResource(R.drawable.icon_my_peisong_green);
            ivMyEvaluation.setImageResource(R.drawable.icon_my_evaluation_green);
            ivMyShou.setImageResource(R.drawable.icon_my_shou_green);
        }

        mRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                page = 1;
                mPresenter.myInterestGood(true, false, TYPE_IS_RETAIL + "", page + "", "" + limit);
            }
        });

    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_five;
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void onResume() {
        super.onResume();
        if (EmptyUtil.isEmpty(APP_TOKEN)) {
            tvName.setText("登录/注册");
            ivMyHead.setImageResource(R.drawable.icon_my_head);

        } else {
             setInfo();
//            ImageGlideUtil.loadAvatar(getActivity(),ivMyHead,UtilsData.getPreference(getActivity(), "login").getString("head_url"));
//            tvName.setText(UtilsData.getPreference(getActivity(),"login").getString("nickname"));
            if (EmptyUtil.isNotEmpty(mPresenter))
                mPresenter.getUserinfo(TYPE_IS_RETAIL+"");
        }

    }

    @Subscribe(threadMode = ThreadMode.POSTING)
    public void XXX(HomeTypeMessage messageEvent) {

        if (null != iavBg) {
            if (messageEvent.getMessage() == 0) {

                iavBg.setToColor("#fb9129");
                llState.setBackgroundColor(getResources().getColor(R.color.color_FB9129));
                ivDaizhifu.setImageResource(R.drawable.icon_my_daizhifu_orange);
                ivDaiFahuo.setImageResource(R.drawable.icon_my_dai_fahuo_orange);
                ivPeisong.setImageResource(R.drawable.icon_my_peisong_orange);
                ivMyEvaluation.setImageResource(R.drawable.icon_my_evaluation_orange);
                ivMyShou.setImageResource(R.drawable.icon_my_shou_orange);
            } else {

                iavBg.setToColor("#02C557");
                llState.setBackgroundColor(getResources().getColor(R.color.color_02C557));
                ivDaizhifu.setImageResource(R.drawable.icon_my_daizhifu_green);
                ivDaiFahuo.setImageResource(R.drawable.icon_my_dai_fahuo_green);
                ivPeisong.setImageResource(R.drawable.icon_my_peisong_green);
                ivMyEvaluation.setImageResource(R.drawable.icon_my_evaluation_green);
                ivMyShou.setImageResource(R.drawable.icon_my_shou_green);
            }
            page = 1;
            mPresenter.myInterestGood(true, false, TYPE_IS_RETAIL + "", page + "", "" + limit);

        }
    }

    @Subscribe(threadMode = ThreadMode.POSTING)
    public void XXXX(MyInfoRefreshMessage messageEvent) {

        setInfo();
    }

    /**
     * 点击我饿刷新关注和浏览记录数量
     */
    @Subscribe(threadMode = ThreadMode.POSTING)
    public void XX(FiveFragmentClickMessage messageEvent) {

        mPresenter.getUserinfo(TYPE_IS_RETAIL+"");
    }

    @Override
    public void onError(Throwable throwable) {

    }

    @Override
    public void onMyInterestGoodSuccess(BuyOftenGoodsBeen bean) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            if (page == 1) {
                mList.clear();
                mRefreshLayout.setNoMoreData(false);
                mRefreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
                    @Override
                    public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                        mPresenter.myInterestGood(false, false, TYPE_IS_RETAIL + "", page + "", limit + "");
                    }
                });
            }
            if (bean.getData().size() == 0) {
//                if (page==1){
//                    tvCantFind.setVisibility(View.VISIBLE);
//                }
                mRefreshLayout.finishLoadMoreWithNoMoreData();
            } else {
                page++;
                mList.addAll(bean.getData());
                oftenBuyAdapter.notifyDataSetChanged();
            }
        } else {
//            Toast.makeText(getActivity(), bean.getMsg(), Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onPosterSuccess(PosterBeen bean) {

    }

    @Override
    public void finishRefresh() {
        mRefreshLayout.finishRefresh(true);
    }

    @Override
    public void finishLoadMore() {
        mRefreshLayout.finishLoadMore(true);
    }

    @Override
    public void getUserInfoSuccess(UserInfoBean bean) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            if (TYPE_IS_RETAIL == 0) {//零售
                if (EmptyUtil.isNotEmpty(bean.getData().getFollow_count())) {
                    tv_shop_focus_num.setText(bean.getData().getFollow_count().getRetail() + "");
                } else {
                    tv_shop_focus_num.setText("0");
                }

                if (EmptyUtil.isNotEmpty(bean.getData().getHistory_list())) {
                    tv_follow_num.setText(bean.getData().getHistory_list().getRetail() + "");
                } else {
                    tv_follow_num.setText("0");
                }

            } else {
                if (EmptyUtil.isNotEmpty(bean.getData().getFollow_count())) {
                    tv_shop_focus_num.setText(bean.getData().getFollow_count().getWholesale() + "");
                } else {
                    tv_shop_focus_num.setText("0");
                }
                if (EmptyUtil.isNotEmpty(bean.getData().getHistory_list())) {
                    tv_follow_num.setText(bean.getData().getHistory_list().getWholesale() + "");
                } else {
                    tv_follow_num.setText("0");
                }

            }
            if (bean.getData().getOrderStatusNum().getTo_be_paid_count() == 0) {
                tvDaiZhi.setVisibility(View.GONE);
            } else {
                tvDaiZhi.setVisibility(View.VISIBLE);
                tvDaiZhi.setText(bean.getData().getOrderStatusNum().getTo_be_paid_count() + "");
            }
            if (bean.getData().getOrderStatusNum().getTo_be_delivered_count() == 0) {
                tvDaiFa.setVisibility(View.GONE);
            } else {
                tvDaiFa.setVisibility(View.VISIBLE);
                tvDaiFa.setText(bean.getData().getOrderStatusNum().getTo_be_delivered_count() + "");
            }
            if (bean.getData().getOrderStatusNum().getGoods_to_be_received_count() == 0) {
                tvDaiShou.setVisibility(View.GONE);
            } else {
                tvDaiShou.setVisibility(View.VISIBLE);
                tvDaiShou.setText(bean.getData().getOrderStatusNum().getGoods_to_be_received_count() + "");
            }
            if (bean.getData().getOrderStatusNum().getTo_be_evaluated_count() == 0) {
                tvDaiPing.setVisibility(View.GONE);
            } else {
                tvDaiPing.setVisibility(View.VISIBLE);
                tvDaiPing.setText(bean.getData().getOrderStatusNum().getTo_be_evaluated_count() + "");
            }
            if (bean.getData().getOrderStatusNum().getRefund_order_count() == 0) {
                tvShouHou.setVisibility(View.GONE);
            } else {
                tvShouHou.setVisibility(View.VISIBLE);
                tvShouHou.setText(bean.getData().getOrderStatusNum().getRefund_order_count() + "");
            }

        } else {
//            Toast.makeText(getActivity(), bean.getMsg(), Toast.LENGTH_SHORT).show();
        }
    }


    private void initHigh() {
        item_bar = (RelativeLayout.LayoutParams) llState.getLayoutParams();
        item_bar.height = StatusBarUtil.getStatusBarHeight(getActivity());
        llState.setLayoutParams(item_bar);
    }

    Intent intent;


    public static FiveFragment newInstance(int userUid) {
        Bundle bundle = new Bundle();
        FiveFragment fragment = new FiveFragment();
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void onDestroy() {
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this);
        }
        super.onDestroy();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {

            case R.id.tv_all_order:
                if (EmptyUtil.isNotEmpty(APP_TOKEN)) {
                    intent = new Intent(getActivity(), AllOrderActivity.class);
                    startActivity(intent);
                } else {
                    intent = new Intent(getActivity(), OneLoginMainActivity.class);
                    startActivity(intent);
                }

                break;
            case R.id.ll_dai_zhi:
                if (EmptyUtil.isNotEmpty(APP_TOKEN)) {
                    intent = new Intent(getActivity(), AllOrderActivity.class);
                    intent.putExtra("from", "my_center");
                    intent.putExtra("position", 1);
                    startActivity(intent);
                } else {
                    intent = new Intent(getActivity(), OneLoginMainActivity.class);
                    startActivity(intent);
                }
                break;
            case R.id.ll_dai_fa:
                if (EmptyUtil.isNotEmpty(APP_TOKEN)) {
                    intent = new Intent(getActivity(), AllOrderActivity.class);
                    intent.putExtra("from", "my_center");
                    intent.putExtra("position", 2);
                    startActivity(intent);
                } else {
                    intent = new Intent(getActivity(), OneLoginMainActivity.class);
                    startActivity(intent);
                }
                break;
            case R.id.ll_dai_shou:
                if (EmptyUtil.isNotEmpty(APP_TOKEN)) {
                    intent = new Intent(getActivity(), AllOrderActivity.class);
                    intent.putExtra("from", "my_center");
                    intent.putExtra("position", 3);
                    startActivity(intent);
                } else {
                    intent = new Intent(getActivity(), OneLoginMainActivity.class);
                    startActivity(intent);
                }
                break;
            case R.id.ll_dai_ping:
                if (EmptyUtil.isNotEmpty(APP_TOKEN)) {
                    intent = new Intent(getActivity(), AllOrderActivity.class);
                    intent.putExtra("from", "my_center");
                    intent.putExtra("position", 4);
                    startActivity(intent);
                } else {
                    intent = new Intent(getActivity(), OneLoginMainActivity.class);
                    startActivity(intent);
                }

                break;
            case R.id.ll_shou_hou:
                if (EmptyUtil.isNotEmpty(APP_TOKEN)) {
                    intent = new Intent(getActivity(), AfterSalesActivity.class);
//                    intent.putExtra("from", "my_center");
//                    intent.putExtra("position", 5);
                    startActivity(intent);
                } else {
                    intent = new Intent(getActivity(), OneLoginMainActivity.class);
                    startActivity(intent);
                }
                break;
            case R.id.ll_shop:
                if (EmptyUtil.isNotEmpty(APP_TOKEN)) {
                    if (UtilsData.getPreference(getActivity(), "login").getInteger("is_store") == 0) {
                        intent = new Intent(getActivity(), MerchantsInActivity.class);
                        startActivity(intent);
                    } else if (UtilsData.getPreference(getActivity(), "login").getInteger("is_store") == 1) {
                        intent = new Intent(getActivity(), MyShopCenterActivity.class);
                        startActivity(intent);
                    }
                } else {

                    intent = new Intent(getActivity(), OneLoginMainActivity.class);
                    startActivity(intent);
                }
                break;
            case R.id.ll_my_shop:
                if (EmptyUtil.isNotEmpty(APP_TOKEN)) {
                    intent = new Intent(getActivity(), MyShopCenterActivity.class);
                    startActivity(intent);
                } else {
                    intent = new Intent(getActivity(), OneLoginMainActivity.class);
                    startActivity(intent);
                }
                break;
            case R.id.ll_my_address:
                if (EmptyUtil.isNotEmpty(APP_TOKEN)) {
                    intent = new Intent(getActivity(), ManagementAddressActivity.class);
                    intent.putExtra("from", "five_my");
                    startActivity(intent);
                } else {
                    intent = new Intent(getActivity(), OneLoginMainActivity.class);
                    startActivity(intent);
                }
                break;
            case R.id.ll_contact_kefu:
                callPhone("15810103429");
                break;
            case R.id.ll_feedback:
                if (EmptyUtil.isNotEmpty(APP_TOKEN)) {
                    intent = new Intent(getActivity(), FeedbackActivity.class);
                    startActivity(intent);
                } else {
                    intent = new Intent(getActivity(), OneLoginMainActivity.class);
                    startActivity(intent);
                }
                break;
            case R.id.ll_my_evaluation:
                intent = new Intent(getActivity(), MyRemakeActivity.class);
                startActivity(intent);
                break;
            case R.id.ll_recommended_prize:
                intent = new Intent(getActivity(), RecommendedActivity.class);
                intent.putExtra("title","推荐有奖");
                startActivity(intent);
                break;
            case R.id.ll_set://设置
            case R.id.iv_my_head://头像和名称未登录点击跳转登录
            case R.id.tv_name://头像和名称未登录点击跳转登录
                if (EmptyUtil.isNotEmpty(APP_TOKEN)) {
                    intent = new Intent(getActivity(), SettingActivity.class);
                    startActivity(intent);
                } else {
                    intent = new Intent(getActivity(), OneLoginMainActivity.class);
                    startActivity(intent);
                }
                break;
            case R.id.iv_message://头像和名称未登录点击跳转登录
                Intent intent = new Intent(getActivity(), MessageActivity.class);
                startActivity(intent);
                break;
            case R.id.ll_shopfocus://店铺关注
                if (EmptyUtil.isNotEmpty(APP_TOKEN)) {
                    intent = new Intent(getActivity(), ShopFocusActivity.class);
                    intent.putExtra("type", TYPE_IS_RETAIL);
                    startActivity(intent);
                } else {
                    intent = new Intent(getActivity(), OneLoginMainActivity.class);
                    startActivity(intent);
                }

                break;
            case R.id.ll_coupon://优惠券
                if (EmptyUtil.isNotEmpty(APP_TOKEN)) {
                    intent = new Intent(getActivity(), CouponActivity.class);

                    startActivity(intent);
                } else {
                    intent = new Intent(getActivity(), OneLoginMainActivity.class);
                    startActivity(intent);
                }

                break;
            case R.id.ll_follow://浏览记录
                if (EmptyUtil.isNotEmpty(APP_TOKEN)) {
                    intent = new Intent(getActivity(), MyFollowActivity.class);
                    intent.putExtra("type", TYPE_IS_RETAIL);
                    startActivity(intent);
                } else {
                    intent = new Intent(getActivity(), OneLoginMainActivity.class);
                    startActivity(intent);
                }
                break;
        }
    }

    /**
     * 拨打电话（跳转到拨号界面，用户手动点击拨打）
     *
     * @param phoneNum 电话号码
     */
    public void callPhone(String phoneNum) {
        Intent intent = new Intent(Intent.ACTION_DIAL);
        Uri data = Uri.parse("tel:" + phoneNum);
        intent.setData(data);
        startActivity(intent);
    }

    private void setInfo() {
        if (null != UtilsData.getPreference(getActivity(), "login").getString("nickname")) {
            tvName.setText(UtilsData.getPreference(getActivity(), "login").getString("nickname"));
        }
        if (UtilsData.getPreference(getActivity(), "login").getInteger("is_store") == 0) {
            tvShopRuzhu.setText("商家入驻");
            UtilsData.getPreference(getActivity(), "ruzhu").remove("shopIn3");
        } else if (UtilsData.getPreference(getActivity(), "login").getInteger("is_store") == 1) {
            tvShopRuzhu.setText("我的店铺");
            UtilsData.getPreference(getActivity(), "ruzhu").remove("shopIn3");
        }
        if (null != UtilsData.getPreference(getActivity(), "login").getString("head_url")) {
            RoundedCorners roundedCorners = new RoundedCorners(20);
            //通过RequestOptions扩展功能,override:采样率,因为ImageView就这么大,可以压缩图片,降低内存消耗
            RequestOptions options = RequestOptions.bitmapTransform(roundedCorners).override(200, 200);
            options.placeholder(R.drawable.icon_my_head)//图片加载出来前，显示的图片
                    .fallback(R.drawable.icon_my_head) //url为空的时候,显示的图片
                    .error(R.drawable.icon_my_head);
            Glide.with(this).load(UtilsData.getPreference(getActivity(), "login").getString("head_url")).apply(options.transform(new CircleCrop(), roundedCorners)).into(ivMyHead);
        }
    }
}
